<?php
include 'session.php';

$main_page = 'location:../battle.php';

mysql_connect('localhost', 'root');
mysql_select_db('dots');

$userID = $_SESSION['userID'];
$battleID = $_SESSION['battleID'];

$query = "SELECT autorID, guestID FROM battles WHERE battleID=$battleID AND finish=0";
$result = mysql_query($query);

if (!$result)
{
	header($main_page);
	exit;
}

$row = mysql_fetch_array($result);
if (!$row)
{
	header($main_page);
	exit;
}

if ($userID == $row[0])
	$turn = 0;
elseif ($userID == $row[1])
	$turn = 1;
else
{
	header($main_page);
	exit;
}
$query = "UPDATE battles SET turn=$turn, finish=1 WHERE battleID=$battleID";
mysql_query($query);

header($main_page);
?>